package de.tum.wi.som.rcpsp.test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jfree.ui.RefineryUtilities;

import de.tum.wi.som.rcpsp.business.impl.SerialGenerationSchemeAlgorithm;
import de.tum.wi.som.rcpsp.entities.Activity;
import de.tum.wi.som.rcpsp.entities.Schedule;
import de.tum.wi.som.rcpsp.entities.WorkContentResource;
import de.tum.wi.som.rcpsp.view.RCPSPBarChart;

public class OwnTestexample {

	public static void main(String[] args) {
		List<Activity> activityList = createActivityList();
		Schedule schedule = new SerialGenerationSchemeAlgorithm()
				.createSchedule(activityList, new WorkContentResource(
						2, 8));

		System.out.println(schedule);
		
		RCPSPBarChart stackedbarchartdemo7 = new RCPSPBarChart("RCPSP", schedule, activityList);
		stackedbarchartdemo7.pack();
		RefineryUtilities.centerFrameOnScreen(stackedbarchartdemo7);
		stackedbarchartdemo7.setVisible(true);

	}

	private static List<Activity> createActivityList() {
		List<Activity> activities = new ArrayList<Activity>();
		Activity activity1 = createActivity("1", 16, new HashSet<Activity>(),
				new HashSet<Activity>(), 2, 7);
		activities.add(activity1);

		Set<Activity> oneAsPrior = new HashSet<Activity>();
		oneAsPrior.add(activity1);
		Activity activity2 = createActivity("2", 27, oneAsPrior,
				new HashSet<Activity>(), 2, 5);
		activities.add(activity2);

		activity1.addFollowerActivity(activity2);

		Activity activity3 = createActivity("3", 12, oneAsPrior,
				new HashSet<Activity>(), 4, 6);
		activities.add(activity3);
		
		activity1.addFollowerActivity(activity3);
		
		Set<Activity> threeAsPrior = new HashSet<Activity>();
		threeAsPrior.add(activity3);
		
		Activity activity4 = createActivity("4", 8, threeAsPrior,
				new HashSet<Activity>(), 2, 3);
		activities.add(activity4);
		activity3.addFollowerActivity(activity4);
		
		Set<Activity> fourAsPrior = new HashSet<Activity>();
		fourAsPrior.add(activity4);
		
		Activity activity5 = createActivity("5", 6, fourAsPrior,
				new HashSet<Activity>(), 1, 3);
		activities.add(activity5);
		activity4.addFollowerActivity(activity5);
		
		
		return activities;
	}

	private static Activity createActivity(String name, int neededResources,
			Set<Activity> priors, Set<Activity> followers, int lowerBound,
			int upperBound) {
		Activity activity = new Activity(name, neededResources, lowerBound,
				upperBound);

		for (Activity follower : followers) {
			activity.addFollowerActivity(follower);
		}

		for (Activity prior : priors) {
			activity.addPriorActivity(prior);
		}
		return activity;
	}

}
